<template>
	<view class="head-box">
		<view class="head-left">
			<image style="width: 60rpx;" src="@/static/logo.png" mode="widthFix"></image>
		</view>
		<view class="head-right">
			<image style="width: 40rpx; display: inline-block;" src="@/static/fill-earth.png" mode="widthFix"></image>
			<uni-data-select style="display: inline-block;" v-model="languageValue" :localdata="range"
				@change="changeClick" :clear="false" />
		</view>
	</view>
</template>

<script>
	import {
		initVueI18n
	} from '@dcloudio/uni-i18n'
	import messages from '@/locale/index';
	const {
		t
	} = initVueI18n(messages)
	export default {
		name: 'headBox',
		data() {
			return {
				languageValue: '0',
				flage: false,
				range: [{
						value: '0',
						text: this.$t('locale.zh-hans')
					},
					{
						value: '1',
						text: this.$t('locale.en')
					},
				],
			}
		},
		created() {
			this.languageValue = uni.getStorageSync('language_key') || '0';
		},
		methods: {
			changeClick(e) {
				uni.setLocale(e === '0' ? 'zh-Hans' : 'en')
				this.languageValue = e;
				uni.setStorage({
					key: 'language_key',
					data: this.languageValue,
				});
				window.location.reload()
			},
		}
	}
</script>

<style scoped lang="scss">
	.head-box {
		display: flex;
		justify-content: space-between;
		padding: 24rpx 32rpx;
		z-index: 999;

		.head-left {
			display: flex;
			align-items: center;
		}

		.head-right {
			display: flex;
			align-items: center;
			margin-right: 64rpx;
		}

		/deep/ .uni-select {
			border: none;
		}

		/deep/ .uni-select__input-text {
			font-weight: 700;
			margin-right: 10rpx;
		}
	}
</style>
